﻿using System;
using System.Windows.Input;
using Cirrious.MvvmCross.Commands;
using TeaLightV5.Foundation.BL;
using TeaLightV5.Foundation.Sal.Interfaces;
using TeaLightV5.Foundation.UX.Interfaces.Models;

namespace TeaLightV5.Foundation.UX.ViewModels
{
    public abstract class ReadEntityViewModel<T, TE, TKey>
        : UpdateEntityViewModel<T, TE, TKey>
        where T : IEntityModel<TE, TKey>, new()
        where TE : class, IEntity<TKey>, new()
         
    {
        protected ReadEntityViewModel(ModelParameters<TKey> parameters) 
            : base(parameters)
        {
            //Speaker = DataStore.GetSpeaker(parameters.Id);
        }

        public abstract ICommand ReadCommand { get; }

        public abstract ICommand EditCommand { get; }
        //{
        //    get
        //    {
        //        return new MvxRelayCommand(
        //            () =>
        //            {
        //                RequestNavigate<SpeakerEditViewModel>(new SpeakerModelParameters() { Id = Speaker.ID });
        //            });
        //    }
        //}

        public ICommand DeleteCommand
        {
            get
            {
                return new MvxRelayCommand(Delete);
            }
        }

        protected virtual void Delete()
        {
            try
            {
                ClearException();
                Repository.Delete(Data.Id);
                RequestClose(this);
            }
            catch (Exception exception)
            {
                HandleException(exception);
            }
        }
    }
}
